home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / da / push.sit / Push C code < prev    next >
Text File  |  2000-05-23  |  10KB  |  281 lines

  1. /* ----------------- push ----------------- 
  2.  *
  3.  * A little guy will push away your screen.
  4.  * What a brutality!!
  5.  * You will have to restart the system after you're through
  6.  * watching him!
  7.  * Written in Aztec C.
  8.  * 
  9.  * Author:   Fons Rademakers
  10.  *           Nikhef-h (Nat. Inst. for High Energy Physics)
  11.  *           the Netherlands
  12.  * Version:  21-nov-1985
  13.  * Revision:
  14.  *
  15.  */
  16.  
  17. #asm
  18. main
  19.     dc.w  $6400        ;ctl-enable, need time and locked in mem.
  20.     dc.w  0          ;update as often as possible
  21.     dc.w  $0001        ;don't react on any specific event
  22.     dc.w  0            ;no menu
  23.  
  24.     dc.w  open_-main    ;open routine
  25.     dc.w  nop_-main        ;prime routine
  26.     dc.w  control_-main    ;control routine
  27.     dc.w  nop_-main        ;status routine
  28.     dc.w  close_-main     ;close routine
  29.  
  30. title_
  31.     dc.b  4
  32.     dc.b  "Push"
  33.     ds    0              ;for alignment
  34.  
  35.     public   _Uend_,_Dorg_,_Cend_
  36.  
  37. save_
  38.     lea     main+(_Uend_-_Dorg_)+(_Cend_-main),a4    ;set up globals
  39.     move.l  a0,Pbp_                    ;save pb pointer
  40.     move.l  a1,Dp_                    ;save DCE pointer
  41.     rts
  42.  
  43. restore_
  44.     move.l  Pbp_,a0
  45.     rts
  46. #endasm
  47.  
  48. #define     _DRIVER
  49. #define  SMALL_MEM
  50. #include <quickdraw.h>
  51. #include <memory.h>
  52. #undef   SMALL_MEM
  53. #include <event.h>
  54. #include <pb.h>
  55. #include <desk.h>
  56.  
  57. #define notSrcCopy     4 /* Not in QD with SMALL_MEM flag set */
  58. #define NULL  (0L)
  59.  
  60. #define BASE1 512        /* Mac screen size in x direction */
  61. #define BASE2 342        /* Mac screen size in y direction */
  62.  
  63. #define SP (*(struct storage **)Dp->dCtlStorage)
  64.  
  65. DCEPtr  Dp;
  66. ParmBlkPtr  Pbp;
  67.  
  68. Rect wind_rect = {0, 0, 0, 0};
  69.  
  70. struct storage {
  71.     GrafPtr pushport;            /* the push grafport */
  72.     BitMap  manmap[3];           /* the 3 amn bitmaps */
  73.     Pattern black;
  74.     short   portspace[54];       /* space for the flowport */
  75.     char    manspace[3][348];    /* space for the 3 man bitmaps */
  76.     short   x;
  77. };
  78.  
  79. open()
  80. {
  81.     register WindowPtr wp;
  82.     register struct DCE *dp;
  83.     register struct storage *sp;
  84.     extern char title[];
  85.     struct windowpeek {
  86.         GrafPort port;
  87.         int      windowKind;
  88.     };
  89.     short    i;
  90.  
  91.     save();
  92.     dp = Dp;
  93.     if (dp->dCtlWindow == NULL) {
  94.         HLock(dp->dCtlStorage = NewHandle((long) sizeof(struct storage)));
  95.         sp = SP;
  96.         /* create an invisible window */
  97.         dp->dCtlWindow =         
  98.         wp = NewWindow(NULL, &wind_rect, title, FALSE, plainDBox, -1L, FALSE, 
  99. NULL);
  100.         ((struct windowpeek *)wp)->windowKind = dp->dCtlRefNum;
  101.         /* allocate space for new pushport */
  102.         &sp->pushport->device = sp->portspace;
  103.         OpenPort(sp->pushport);
  104.         /* set the 3 man bitmaps */
  105.         for (i = 0; i < 3 ; i++) {
  106.            sp->manmap[i].bounds.top    = 0;
  107.             sp->manmap[i].bounds.left   = 0;
  108.             sp->manmap[i].bounds.bottom = 58;
  109.             sp->manmap[i].bounds.right  = 48;
  110.             sp->manmap[i].rowBytes      = 6;
  111.             sp->manmap[i].baseAddr      = &sp->manspace[i][0];
  112.         }
  113.           /* first man map */
  114.           StuffHex(sp->manmap[0].baseAddr,    "\P00000000001000000000001800000000001C");
  115.         StuffHex(sp->manmap[0].baseAddr+18, "\P000000000020000000000040000000000080");
  116.         StuffHex(sp->manmap[0].baseAddr+36, "\P000000000100000000000200000000000400");
  117.         StuffHex(sp->manmap[0].baseAddr+54, "\P000000000800000000001000000000002000");
  118.         StuffHex(sp->manmap[0].baseAddr+72, "\P003F00004000007F80008000007C80010000");
  119.         StuffHex(sp->manmap[0].baseAddr+90, "\P007900220000007080740000002100E80000");
  120.         StuffHex(sp->manmap[0].baseAddr+108,"\P001083240000001F0CDE0000002173240000");
  121.         StuffHex(sp->manmap[0].baseAddr+126,"\P004784C800000041CB10000000403C200000");
  122.         StuffHex(sp->manmap[0].baseAddr+144,"\P004000C0000000438300000000407C000000");
  123.         StuffHex(sp->manmap[0].baseAddr+162,"\P004080000000004080000000004080000000");
  124.         StuffHex(sp->manmap[0].baseAddr+180,"\P004080000000002080000000003F80000000");
  125.         StuffHex(sp->manmap[0].baseAddr+198,"\P002080000000002080000000001080000000");
  126.         StuffHex(sp->manmap[0].baseAddr+216,"\P001100000000001100000000001100000000");
  127.         StuffHex(sp->manmap[0].baseAddr+234,"\P001100000000001100000000001100000000");
  128.         StuffHex(sp->manmap[0].baseAddr+252,"\P001100000000001200000000001200000000");
  129.         StuffHex(sp->manmap[0].baseAddr+270,"\P001200000000001200000000001200000000");
  130.         StuffHex(sp->manmap[0].baseAddr+288,"\P001200000000003F00000000003F00000000");
  131.         StuffHex(sp->manmap[0].baseAddr+306,"\P003F00000000001200000000001200000000");
  132.         StuffHex(sp->manmap[0].baseAddr+324,"\P0012000000000013C0000000001420000000");
  133.         StuffHex(sp->manmap[0].baseAddr+342,"\P001BE0000000");
  134.  
  135.           /* second man map */
  136.          StuffHex(sp->manmap[1].baseAddr,    "\P00000000001000000000001800000000001C");
  137.         StuffHex(sp->manmap[1].baseAddr+18, "\P000000000020000000000040000000000080");
  138.         StuffHex(sp->manmap[1].baseAddr+36, "\P000000000100000000000200000000000400");
  139.         StuffHex(sp->manmap[1].baseAddr+54, "\P000000000800000000001000000000002000");
  140.         StuffHex(sp->manmap[1].baseAddr+72, "\P003F00004000007F80008000007C80010000");
  141.         StuffHex(sp->manmap[1].baseAddr+90, "\P007900220000007080740000002100E80000");
  142.         StuffHex(sp->manmap[1].baseAddr+108,"\P001083240000001F0CDE0000002173240000");
  143.         StuffHex(sp->manmap[1].baseAddr+126,"\P004784C800000041CB10000000403C200000");
  144.         StuffHex(sp->manmap[1].baseAddr+144,"\P004000C0000000438300000000407C000000");
  145.         StuffHex(sp->manmap[1].baseAddr+162,"\P004080000000004080000000004080000000");
  146.         StuffHex(sp->manmap[1].baseAddr+180,"\P004080000000002080000000003F80000000");
  147.         StuffHex(sp->manmap[1].baseAddr+198,"\P002080000000002080000000001080000000");
  148.         StuffHex(sp->manmap[1].baseAddr+216,"\P001080000000001080000000001240000000");
  149.         StuffHex(sp->manmap[1].baseAddr+234,"\P001240000000001220000000001320000000");
  150.         StuffHex(sp->manmap[1].baseAddr+252,"\P002310000000002690000000004488000000");
  151.         StuffHex(sp->manmap[1].baseAddr+270,"\P00484800000000884C000000009024000000");
  152.         StuffHex(sp->manmap[1].baseAddr+288,"\P01102400000003F07E00000003F07E000000");
  153.         StuffHex(sp->manmap[1].baseAddr+306,"\P03F07E000000012024000000012024000000");
  154.         StuffHex(sp->manmap[1].baseAddr+324,"\P012024000000013C27800000014228400000");
  155.         StuffHex(sp->manmap[1].baseAddr+342,"\P01BE37C00000");
  156.  
  157.           /* third man map */
  158.           StuffHex(sp->manmap[2].baseAddr,    "\P00000000001000000000001800000000001C");
  159.         StuffHex(sp->manmap[2].baseAddr+18, "\P000000000020000000000040000000000080");
  160.         StuffHex(sp->manmap[2].baseAddr+36, "\P000000000100000000000200000000000400");
  161.         StuffHex(sp->manmap[2].baseAddr+54, "\P000000000800000000001000000000002000");
  162.         StuffHex(sp->manmap[2].baseAddr+72, "\P003F00004000007F80008000007C80010000");
  163.         StuffHex(sp->manmap[2].baseAddr+90, "\P007900220000007080740000002100E80000");
  164.         StuffHex(sp->manmap[2].baseAddr+108,"\P001083240000001F0CDE0000002173240000");
  165.         StuffHex(sp->manmap[2].baseAddr+126,"\P004784C800000041CB10000000403C200000");
  166.         StuffHex(sp->manmap[2].baseAddr+144,"\P004000C0000000438300000000407C000000");
  167.         StuffHex(sp->manmap[2].baseAddr+162,"\P004080000000004080000000004080000000");
  168.         StuffHex(sp->manmap[2].baseAddr+180,"\P004080000000002080000000003F80000000");
  169.         StuffHex(sp->manmap[2].baseAddr+198,"\P002080000000002080000000001080000000");
  170.         StuffHex(sp->manmap[2].baseAddr+216,"\P001080000000001080000000001240000000");
  171.         StuffHex(sp->manmap[2].baseAddr+234,"\P001240000000001220000000001320000000");
  172.         StuffHex(sp->manmap[2].baseAddr+252,"\P002310000000004490000000008888000000");
  173.         StuffHex(sp->manmap[2].baseAddr+270,"\P01104800000006204C0000000F4024000000");
  174.         StuffHex(sp->manmap[2].baseAddr+288,"\P0F802400000017807E00000023007E000000");
  175.         StuffHex(sp->manmap[2].baseAddr+306,"\P44007E000000880024000000D00024000000");
  176.         StuffHex(sp->manmap[2].baseAddr+324,"\P480024000000240027800000120028400000");
  177.         StuffHex(sp->manmap[2].baseAddr+342,"\P0E0037C00000");
  178.  
  179.         /* set start x value */
  180.         sp->x = 0;
  181.         /* black pattern */
  182.         StuffHex(sp->black, "\PFFFFFFFFFFFFFFFF");
  183.         /* set the background pattern to black */
  184.         BackPat(sp->black);
  185.  
  186.         HUnlock(dp->dCtlStorage);
  187.     }
  188.     restore();
  189.     return(0);
  190. }
  191.  
  192.  
  193. close()
  194. {
  195.     register struct DCE *dp;
  196.  
  197.     save();
  198.     dp = Dp;
  199.     /* get rid of the allocated space for the window */
  200.     DisposeWindow(dp->dCtlWindow);
  201.     dp->dCtlWindow = NULL;
  202.     DisposHandle(dp->dCtlStorage);
  203.     restore();
  204.     return(0);
  205. }
  206.  
  207.  
  208. nop()
  209. {
  210.     return(0);
  211. }
  212.  
  213.  
  214.  
  215.  
  216. control()
  217. {
  218.     register struct DCE *dp;
  219.     register struct storage *sp;
  220.     short     i, j;
  221.     short     xdest, ydest;
  222.     short     xvel, slowdown;
  223.     Rect      destrect;
  224.     RgnHandle dummyrgn;
  225.  
  226.     save();
  227.     dp = Dp;
  228.     HLock(dp->dCtlStorage);
  229.     sp = SP;
  230.     switch (Pbp->u.cp.csCode) {
  231.     case accRun:        /* time to push the screen */
  232.         SetPort(sp->pushport);
  233.  
  234.         xvel = 2;    /* speed with which the screen is being pushed by the man 
  235. */
  236.  
  237.         /* to prevent man from walking too fast at end of screen, slow him down 
  238. */ 
  239.         if (sp->x < 128)        /* 1/4*BASE1 */
  240.            slowdown = 0;
  241.         else if (sp->x < 256)   /* 1/2*BASE1 */
  242.            slowdown = 1000;
  243.         else if (sp->x < 384)   /* 3/4*BASE1 */
  244.             slowdown = 5000;
  245.         else
  246.             slowdown = 10000;
  247.  
  248.         for (i = 0; i < 3; i++) {
  249.            for (j = 0; j <= slowdown; j++)
  250.                ;
  251.           if (sp->x <= BASE1 + 48) {
  252.                dummyrgn = NewRgn();
  253.                SetRect(&destrect, sp->x, 0, BASE1, BASE2);
  254.                xdest = xvel;
  255.                ydest = 0;
  256.                ScrollRect(&destrect, xdest, ydest, dummyrgn);
  257.                sp->x += xvel;
  258.  
  259.                 /* kind of dirty fix: erase heel of third man map.
  260.                  * I should have defined the man maps 1 word bigger on the left side
  261.                  * to prevent this EraseRect call */
  262.                 if (!i) {
  263.                     SetRect(&destrect, sp->x - 56, BASE2 - 13, sp->x - 48, BASE2);
  264.                     EraseRect(&destrect);
  265.                 }
  266.  
  267.                 SetRect(&destrect, sp->x - 48, BASE2 - 58, sp->x, BASE2);
  268.                 CopyBits(&sp->manmap[i], &sp->pushport->portBits,
  269.                          &sp->manmap[i].bounds, &destrect,
  270.                             notSrcCopy, NULL);
  271.                DisposeRgn(dummyrgn);
  272.             } else 
  273.                 sp->x = 0;
  274.         }
  275.     break;  /* end case */
  276.     }
  277.     HUnlock(dp->dCtlStorage);
  278.     restore();
  279.     return(0);
  280. }
  281.